package netty.io.demo.BIO;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Client {
  
  public static void main(String[] args) throws IOException {
    // socket 必备
    Socket socket = null;
    
    // 输入输出 流
    ObjectInputStream in = null;
    ObjectOutputStream out = null;
    
    // 绑定 端口以及ip 地址
    InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10001);
    
    try {
      // 实例 socket
      socket = new Socket();
      socket.connect(addr);
      
      out = new ObjectOutputStream(socket.getOutputStream());
      in = new ObjectInputStream(socket.getInputStream());
      
      // 向 客户端 发送数据
      out.writeUTF("client");
      out.flush();
      
      // 接受服务端的输出
      System.out.println(in.readUTF());
    } finally {
      if (socket != null)
        socket.close();
      if (in != null)
        in.close();
      if (out != null)
        out.close();
    }
  }
}
